﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Adultorama.Ctrl;
using Adultorama.Model;

namespace Adultorama.Gui
{
    public partial class UserMenuPanel : UserControl
    {
        Adultorama parent;
        public UserMenuPanel(Adultorama parent)
        {
            InitializeComponent();
            this.parent = parent;
        }
        void hidePanels()
        {
            parent.bookingPanel.Visible = false;
            this.userMenuBookingButton.ForeColor = Color.Black;

            parent.deleteBookingPanel.Visible = false;
            this.deleteBookingButton.ForeColor = Color.Black;
        }
        private void userMenuBookingButton_Click(object sender, EventArgs e)
        {
            hidePanels();

            if (sender.Equals(userMenuBookingButton))
            {
                parent.bookingPanel.bookingShowListView.Items.Clear();
                this.userMenuBookingButton.ForeColor = Color.Red;
                BookingControler bookingCtrl = new BookingControler();
                List<Show> showList = bookingCtrl.getShows();
                int i = 0;
                foreach (Show s in showList)
                {
                    string[] row1 = { s.showId.ToString(), s.movie.title, "s3" };
                    parent.bookingPanel.bookingShowListView.Items.Add(s.movie.title).SubItems.AddRange(row1);
                    i++;
                }
                parent.bookingPanel.Visible = true;
            }
            if (sender.Equals(deleteBookingButton))
            {
                parent.deleteBookingPanel.Visible = true;
                this.deleteBookingButton.ForeColor = Color.Red;
                parent.deleteBookingPanel.deleteBookingListView.Items.Clear();
                BookingControler bookingCtrl = new BookingControler();
                List<Show> showList = bookingCtrl.getShows();
                List<Ticket> ticketList = bookingCtrl.getBookings();
                int i = 0;
                foreach (Ticket t in ticketList)
                {
                    Boolean found = false;
                    string movieTitle = "";
                    int showCount = 0;
                    while (!found || showCount < showList.Count) {
                        if (showList[showCount].showId == t.showId) {
                            movieTitle = showList[showCount].movie.title;
                            found = true;
                        }
                        showCount++;
                    }
                    string[] row1 = { movieTitle, t.id.ToString() };
                    parent.deleteBookingPanel.deleteBookingListView.Items.Add(t.phoneNumber.ToString()).SubItems.AddRange(row1);
                    i++;
                }
            }
            if (sender.Equals(LogOutButton))
            {
                parent.logInPanel.Visible = true;
                this.Visible = false;
            }
        }
    }
}
